home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / get_info.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-22  |  7.8 KB  |  226 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: get_info.c,v 1.4 89/06/06 08:38:07 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/get_info.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/get_info.c,v $$Revision: 1.4 $";
  12.  
  13. /* return info to shell */
  14.  
  15. #include "bitmap.h"
  16. #include "font.h"
  17. #include "defs.h"
  18. #include "menu.h"
  19. #include "event.h"
  20. #include <stdio.h>
  21. #include "window.h"
  22.  
  23. /*    BUTTON_SYS is never reported as a possible button setting. */
  24. #define    RPT_BUTTON()    (button_state == BUTTON_SYS ? 0 : button_state )
  25.  
  26. get_info(win,window,text)
  27. register WINDOW *win;            /* window info is about */
  28. BITMAP *window;                /* window's bitmap data */
  29. BITMAP *text;                /* window's text region */
  30.    {
  31.    int cnt = W(esc_cnt);        /* # of leading ESC #'s */
  32.    int count;                /* whatever */
  33.    char font_buff[MAX_PATH];        /* space to store a path name */
  34.    char coords[1024];            /* space for return value */
  35.     char *start = coords;        /* start of reply */
  36.    register WINDOW *win2;        /* generic window pntr */
  37.    struct font *Get_font();
  38.  
  39.     if (W(flags)&W_DUPKEY) {
  40.         sprintf(coords,"%c ",W(dup));
  41.         start += strlen(coords);
  42.         }
  43.     else
  44.         *coords = '\0';
  45.  
  46.    if (cnt == 1) {        /* info about spot */
  47.       for(win2=active;win2!=(WINDOW *) 0;win2=win2->next)
  48.          if (mousein(W(esc)[0],W(esc)[1],win2,1))
  49.             break;
  50.       if (win2 != (WINDOW *) 0)
  51.          sprintf(start,"%s %s %d %d\n",
  52.                   win->tty+strlen(win->tty)-2,
  53.                   win2->tty+strlen(win2->tty)-2,win2->num,win2->pid);
  54.       else
  55.          sprintf(start,"\n");
  56.       Write(W(to_fd),coords,strlen(coords));
  57.       return;
  58.       }
  59.       
  60. #ifdef DEBUG
  61.    dprintf(i)(stderr,"%s: getting info %d\r\n",W(tty),*W(esc));
  62. #endif
  63.    switch (W(esc)[0]) {
  64.       case G_TERMCAP:    /* send termcap entry back to shell */
  65.            {
  66.            int lines = T_HIGH/FSIZE(high);
  67.            int cols  = T_WIDE/FSIZE(wide);
  68.            sprintf(start,"%s:am:li#%d:co#%d:bs:cl=^L:ce=\\E%c:cd=\\E%c:cm=\\E%%r%%d%c%%d%c:al=\\E%c:dl=\\E%c:ic=\\E%c:dc=\\E%c:im=:ta=^I:up=\\E%c:do=\\E%c:nd=\\E%c:ku=\\E[A:kd=\\E[B:kr=\\E[C:kl=\\E[D:so=\\E%c:se=\\E%c:vs=\\E%c:ve=\\E%c:\n",
  69.                    C_NAME,lines,cols,E_CLEAREOL,E_CLEAREOS,
  70.                    E_SEP1,E_CUP,E_ADDLINE,E_DELETELINE,E_ADDCHAR,E_DELETECHAR, 
  71.                    E_UPLINE,E_DOWN,E_RIGHT,E_STANDOUT,E_STANDEND,
  72.                    E_VI,E_NOVI);
  73.            }
  74.            break;
  75.       case G_WINSIZE:                    /* cols, lines */
  76.            sprintf(start,"%d %d\n", T_WIDE/FSIZE(wide),
  77.               T_HIGH/FSIZE(high));
  78.            break;
  79.       case G_FONT:                    /* font wide, high, # */
  80.            {
  81.            register int id = W(font)->ident;
  82.            sprintf(start,"%d %d %d %s\n", FSIZE(wide),
  83.               FSIZE(high),id,id>0?fontlist[id-1]:
  84.               "default.fnt");
  85.            }
  86.            break;
  87.       case G_CURSOR:                    /* x,y gx,gy cursor_type */
  88.            sprintf(start,"%d %d %d %d %d\n",
  89.               W(x)/FSIZE(wide),
  90.               W(y)/FSIZE(high)-1,
  91.               W(gx), W(gy),
  92.               W(curs_type));
  93.            break;
  94.       case G_TEXT:            /* text region size: x,y,wide,high */
  95.            sprintf(start,"%d %d %d %d\n",
  96.               W(text.x),W(text.y),W(text.wide),W(text.high));
  97.            break;
  98.       case G_MOUSE:                    /* mouse coordinates */
  99.            sprintf(start,"%d %d %d\n", mousex, mousey, RPT_BUTTON());
  100.            break;
  101.       case G_MOUSE2:                /* massaged coordinates */
  102.            if (W(flags)&W_ABSCOORDS)
  103.               sprintf(start, "%d %d %d\n", mousex-W(x0), mousey-W(y0), 
  104.                     RPT_BUTTON());
  105.            else
  106.               sprintf(start,"%d %d %d\n",
  107.                     (mousex-W(x0))*GMAX/BIT_WIDE(W(window)),
  108.                     (mousey-W(y0))*GMAX/BIT_HIGH(W(window)),
  109.                     RPT_BUTTON());
  110.            break;
  111.       case G_COORDS:                    /* window coords */
  112.            sprintf(start,"%d %d %d %d\n",W(x0),W(y0),
  113.               WIDE,HIGH);
  114.            break;
  115.       case G_STATUS:                    /* window status */
  116.            sprintf(start,"%c\n",W(flags)&W_ACTIVE
  117.                    ? C_EXPOSED: C_OBSCURED);
  118.            if (win == active)
  119.               *start = C_ACTIVE;
  120.            break;
  121.       case G_ALLMINE:            /* window status for client windows */
  122.       case G_ALL:                /* complete window status */
  123.            {
  124.            register char status;
  125.            for(win2=active;win2!=(WINDOW *) 0;win2=win2->next) {
  126.               if (*W(esc)==G_ALLMINE && win2->main != W(main))
  127.                  continue;
  128.               status = win2->flags&W_ACTIVE ? C_EXPOSED:C_OBSCURED;
  129.               if (win2 == win)
  130.                  status += ('A'-'a');
  131.  
  132.               sprintf(start+strlen(start),"%d %d %d %d %s %d %c %d\n",
  133.                       win2->x0,
  134.                       win2->y0,
  135.                       win2->BIT_WIDE(border),
  136.                       win2->BIT_HIGH(border),
  137.                       win2->tty+strlen(win2->tty)-2,
  138.                       win2->num,
  139.                       status,
  140.                       win2->setid
  141.                       );
  142.                Write(W(to_fd),coords,strlen(coords));
  143.                *coords = '\0';    /* output already processed */
  144.                     start = coords;
  145.                }
  146.            }
  147.            break;
  148.       case G_NOTIFY:            /* list windows with notify set  */
  149.            {
  150.            register char *str;
  151.            for(win2=active;win2!=(WINDOW *) 0;win2=win2->next) {
  152. #ifdef DEBUG
  153.               dprintf(i)(stderr,"  checking %s\r\n",win2->tty);
  154. #endif
  155.               if (IS_EVENT(win2,EVENT_NOTIFY) &&
  156.                     (str = win2->events[GET_EVENT(EVENT_NOTIFY)])) {
  157.  
  158.                  sprintf(start,"%d.%d %d %s\n",
  159.                           win2->pid,win2->num,strlen(str),str);
  160.                  Write(W(to_fd),coords,strlen(coords));
  161. #ifdef DEBUG
  162.                  dprintf(i)(stderr,"    got %s\r\n",str);
  163. #endif
  164.                  *coords = '\0';    /* output already processed */
  165.                  } 
  166.               if (*coords)
  167.                  strcat(coords,"\n");
  168.               }
  169.  
  170.            }
  171.            break;
  172.       case G_SYSTEM:                    /* system status */
  173.            gethostname(start,sizeof(coords));
  174.            sprintf(start+strlen(start)," %d %d %d %d %d\n",
  175.                       BIT_WIDE(screen),
  176.                       BIT_HIGH(screen),
  177.                       SUM_BDR,
  178.                       DEPTH,
  179.                       BITS+1);
  180.            break;
  181.       case G_ID:                    /* client window id */
  182.            for(count=0,win2=W(main);win2;win2=win2->alt)
  183.               count++;
  184.            sprintf(start,"%d %d\n",W(num),count);
  185.            break;
  186.       case G_FLAGS:                    /* window flags */
  187.            sprintf(coords,"%0x %d %d %d\n",
  188.                         W(flags),
  189.                         PUTCOLOR(W(style)),
  190.                         PUTCOLOR(W(background)),
  191.                         PUTCOLOR(W(op)));
  192.  
  193.            break;
  194. #ifdef OBSOLETE
  195.       case G_ALLFONT:                    /* font information */
  196.            {
  197.            register struct font *temp;
  198.            register int i;
  199.  
  200.            sprintf(start,"%d %d",font->head.wide,
  201.                                  font->head.high);
  202.            for(i=0;i<MAXFONT;i++)  {
  203.               temp=Get_font(i);
  204.               sprintf(start+strlen(start), "  %d %d",
  205.                             temp->head.wide,
  206.                             temp->head.high);
  207.               }
  208.            strcat(start,"\n");
  209.            }
  210.            break;
  211. #endif
  212.       default:                                /* invalid request, send back a \n */
  213.            strcat(start,"\n");
  214.            break;
  215.       }
  216.  
  217.    if (strlen(coords))
  218.       Write(W(to_fd),coords,strlen(coords));
  219.     else
  220.       Write(W(to_fd),"\n",1);
  221. #ifdef DEBUG
  222.    dprintf(i)(stderr,"  sending (%d) [%s]\r\n",
  223.                  strlen(coords),coords);
  224. #endif
  225.    }
  226.